import simplejson

class ResponseBase():
    def __init__(self, content_type='text/html; charset=UTF-8'):
        self.headers = {'content_type': content_type}

    def disableBrowserCache(self):
        self.headers.update({
            'Cache-Control': 'no-store, no-cache',
            'Expires': '0', 'Pragma': 'no-cache',
            })

    def render(self, request):
        raise NotImplemented

class TextResponse(ResponseBase):
    def __init__(self, msg):
        ResponseBase.__init__(self, 'text/plain; charset=UTF-8')
        self.msg = msg

    def render(self, request):
        print self.msg
        print simplejson.dumps(self.msg)
        return simplejson.dumps(self.msg)

class HtmlResponse(ResponseBase):
    def __init__(self, msg):
        ResponseBase.__init__(self, 'text/html; charset=UTF-8')
        self.msg = msg

    def render(self, request):
        return self.msg

class RedirectResponse(ResponseBase):
    def __init__(self, url):
        self.url = url

    def render(self, request):
        request.redirect(self.url)
        return ''

class CommandListResponse(ResponseBase):
    def __init__(self, cmdList):
        self.cmdList = cmdList

    def render(self, request):
        print simplejson.dumps(self.cmdList)
        return simplejson.dumps(self.cmdList)
